package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * ClassName: PermissionServiceImpl
 * Description:
 * date: 2019/12/1 20:21
 * Author Airson
 * Since JDK 1.8
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    PermissionDao permissionDao;

    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    @Override
    public void delById(Integer id) {
        permissionDao.delById(id);
    }

    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {

        //开始分页
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //条件查询
        Page<Permission> page = permissionDao.findByCondition(queryPageBean.getQueryString());
        //返回结果
        return new PageResult(page.getTotal(), page);
    }

    @Override
    public void add(Permission permission) {

        permissionDao.add(permission);

    }
}